define(["jquery","validate"],function($,validate){
	
	return {
		
		init : function(){
			//获取dom元素
			var wrap = $("#registerWrap");
			var register = $("#register");
			var btnReg = $(".btnReg");
			var btnLogin = $(".btnLogin");
//			console.log(register.find(".button"));	
			
			//注册按钮单击事件
			btnReg.on("click",function(){
				wrap.css({
					display:"block"
				})
			});

			//注册页面,关闭按钮单击事件
			register.find(".icon-guanbi").on("click",function(){
				wrap.css({
					display:"none"
				})
				
			});
			
//			//引入jquery正则插件,完成前端验证功能
			var validate = $("#register").validate({
				//debug: true, //调试模式取消submit的默认提交功能   
             	rules:{
                    username:{
                        required:true,
                        checkPhone:true,
                        success: function(label) {
						    // set &nbsp; as text for IE
						    $(label).parent().next().text("Ok!");
						    
						}
                    },
                    password:{
                        required:true,
                        rangelength:[8,20],
                         success: function(label) {
						    // set &nbsp; as text for IE
						    $(label).parent().next().text("Ok!");
						    
						}
                    },
                    confirm_password:{
                        equalTo:"#password",
                         success: function(label) {
						    // set &nbsp; as text for IE
						    $(label).parent().next().text("Ok!");
						    
						}
                    }                    
                },
                messages:{
                    username:{
                        required:"账号不能为空",
                        rangelength: "请输入正确格式的账号"
                        
                    },
                    password:{
                        required: "密码不能为空",
                        rangelength: "密码长度8~20"
                    },
                    confirm_password:{
                        equalTo:"两次密码输入不一致"
                    }                                    
                },
                errorPlacement: function(error, element) { 
              		//这里的element指的是input元素
                	console.log($(error).text());
				    element.parent().next().text($(error).text()); 
				},
				submitHandler:function(form){
		            alert("submit!");   
		            form.submit();
		        }    
                
			});
			
			
			//自定义验证方法
//			验证手机号
			$.validator.addMethod("checkPhone",function(value,element,params){
				var checkPhone = /^1[3,5,7,8]\d{9}$/;
				return this.optional(element)||(checkPhone.test(value));
			},"请输入正确格式的手机号！");
			
			$.validator.setDefaults({
				submitHandler: function(form) { alert("submit!"); form.submit(); }
			});
			
		}
		
		
		
		
		
	}
	
	
	
})
